import {useStore} from 'vuex'
import {onShow} from '@dcloudio/uni-app'
export const useGuard = ()=>{
	const store = useStore() //useStore必须在自定义hook内部调用
	onShow(()=>{
		console.log('购物车页面onShow');
		let {userInfo} = store.state.user
		if(!userInfo){
			uni.showModal({
				content:'请登录后再访问购物车',
				confirmText:'立即登录',
				confirmColor:'#857A72',
				cancelText:'稍后再说',
				success({confirm}) {
					console.log(confirm);
					if(confirm){
						uni.navigateTo({
							url:'/pages/login/login'
						})
					}else{
						uni.switchTab({
							url:'/pages/index/index'
						})
					}
				}
			})
		}
	})
}